package com.mango.ch01;

import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class TemperatureReducer extends Reducer<DateTemperaturePair, IntWritable, Text, Text> {

	@Override
	protected void reduce(DateTemperaturePair key, Iterable<IntWritable> values,
			Reducer<DateTemperaturePair, IntWritable, Text, Text>.Context context)
			throws IOException, InterruptedException {
		// TODO Auto-generated method stub
		// redue 拿到的是一组key相同的数据
		StringBuilder sortedList = new StringBuilder();
		for (IntWritable temperature : values) {
			sortedList.append(temperature);
			sortedList.append(",");
		}
		context.write(key.getYearMonth(), new Text(sortedList.toString()));
	}

}
